package com.anjian.action;

import java.util.Date;
import java.util.Map;
import java.util.logging.Logger;

import org.apache.commons.lang.time.DateUtils;

import com.opensymphony.xwork2.ActionContext;

public class CheckIntervalAction extends ActionBase {

	static Logger _log = Logger.getLogger(CheckIntervalAction.class.getName());
	
	private int interval = 5; //minutes
	private boolean limit;
	
	public String execute() throws Exception {
		if (isAdmin())
		{
			limit = false;
			return SUCCESS;
		}
		Map<String, Object> session = ActionContext.getContext().getSession();
		Date lastScan = (Date)session.get(LAST_SCAN);
		if (lastScan != null)
		{
			Long l = lastScan.getTime();
			if (System.currentTimeMillis() - l < DateUtils.MILLIS_PER_MINUTE * interval)
			{
				limit = true;
				return SUCCESS;
			}
		}
		limit = false;
		return SUCCESS;
	}
	
	public boolean isLimit()
	{
		return limit;
	}
	
	public int getInterval()
	{
		return interval;
	}
}
